package by.alex.dzeshko.facebooksuperclient.api;

import android.content.Context;
import by.alex.dzeshko.facebooksuperclient.ContextHolder;
import by.alex.dzeshko.facebooksuperclient.R;
import by.alex.dzeshko.facebooksuperclient.oauth.FBOAuthHelper;

public class ApiRequest {
	
	Context context = ContextHolder.getInstance().getContext();
	
	 private static final String mGraphApi = "https://graph.facebook.com/";

	 private static final String mGraphApiFeed = "/feed";
	 
	 private static final String mGraphApiFriends = "/friends";
	 
	 private static final String mGraphApiLike = "/likes";
	
	 private static final String mGraphApiComment = "/comments";

	 private static final String mGetUser = "?fields=birthday,location,name&access_token=";

	 private static final String mGetStatuses = mGraphApi+"me/statuses&access_token=";
	 
	 private static final String mGetFriends = mGraphApi+"me/friends?access_token=";
	 
	 private static final String mGetNewsFeed = mGraphApi+"me/home";
	 
	 private static final String mGetUserFeed = mGraphApi+"me/feed?access_token=";

	 private static final String mGetFullAppUserProfile = mGraphApi+"me?access_token=";
	 
	 private static final String mOnWallPost = mGraphApi+"me/feed";
	 
	 private static final String mGetProfilePicture = "http://graph.facebook.com/ /picture";
	 
	 public static final int SQUARE = 0;
	 public static final int SMALL = 1;
	 public static final int NORMAL = 2;
	 public static final int LARGE = 3;
	 
	 public static String getBasicApiUrl(String objectId){
		 return mGraphApi+objectId;
	 }

	 public static String getNewsFeed() {
		return mGetNewsFeed;
	 }

	/* public static String getProfileFeedApiUrl(String objectId, int limit){
		 StringBuilder urlBuilder = new StringBuilder(getBasicApiUrl(objectId));
		 urlBuilder.append(mGraphApiFeed).append("&limit=").append(limit);
		 return urlBuilder.toString();
	 }*/
	 
	 public static String getProfileFeedApiUrl(String objectId){
		 StringBuilder urlBuilder = new StringBuilder(getBasicApiUrl(objectId));
		 urlBuilder.append(mGraphApiFeed);
		 return urlBuilder.toString();
	 }
	 
	 public static String getFriends(String id) {
		 String url = getBasicApiUrl(id)+mGraphApiFriends;
		 return addToken(url);
	 }

	 public static String getLikeApiUrl(String objectId){
		 return getBasicApiUrl(objectId)+mGraphApiLike;
	 }
	 
	 public static String getCommentApiUrl(String objectId){
		 String url = getBasicApiUrl(objectId)+mGraphApiComment;
		 return addToken(url);
	 }
	 
	 public static String addToken(String url){  
		 return url+="?access_token=" + FBOAuthHelper.getToken();  
	 }
	 
	 public static String getProfilePicture(String id, int type) {
		 String url = mGetProfilePicture.replace(" ", id);
		 switch (type) {     
		  case SQUARE: url+="?type=square"; break;          
		  case SMALL: break; 
		  case NORMAL: url+="?type=normal"; break; 
		  case LARGE: url+="?type=large";   break;
		  default: break;
		 }
		return url;
	}
	 
	 public static String getProfilePicture(String id, int width, int height) {
		 String url = mGetProfilePicture.replace(" ", id);
		 url=url+"?width="+width+"&height="+height;
		 return url;
	}

	public static String getFullAppUserProfile() {
		return mGetFullAppUserProfile;
	}

	public static String getUserSimple(String id) {
		return mGraphApi + id + mGetUser + FBOAuthHelper.getToken();
	}
	
	public static String getUserId() {
		return mGraphApi +"me?fields=id&access_token=";
	}

	public static String getUserStatuses() {
		return mGetStatuses;
	}

	public static String getUserFeed() {
		return mGetUserFeed;
	}

}
